import redis
from com.util.configUtil import Conf


class RedisCon(object):

    def __init__(self, dbName='quota-online'):
        """
        quota-test
        :param dbName:
        """
        _host = Conf.REDISDB_CONF.getConfVal(dbName, "_host")
        _port = Conf.REDISDB_CONF.getConfVal(dbName, "_port")
        _password = Conf.REDISDB_CONF.getConfVal(dbName, "_password")
        _db = int(Conf.REDISDB_CONF.getConfVal(dbName, "_db"))
        self.redisCon = redis.ConnectionPool(host=_host, db=_db,
                                             port=_port, password=_password,
                                             decode_responses=True, socket_connect_timeout=3)

    def getCon(self) -> object:
        return redis.Redis(connection_pool=self.redisCon, socket_connect_timeout=3)
